/**
 * 当组件滑动时,自动隐藏el-select下拉框
 * 触发el-select的clickoutside事件
 *
 * 使用:将指令添加到包含el-select的外层容器上即可
 */
export default {
  name: 'scroll-view',
  bind (el: HTMLElement) {
    function listenerFn () {
      /**
       * 当form滑动时,自动隐藏el-select下拉框
       * 触发el-select的clickoutside事件
       */
      const evt = new MouseEvent('mouseup', {
        bubbles: true,
        cancelable: true,
        view: window,
        relatedTarget: document
      })
      const evt1 = new MouseEvent('mousedown', {
        bubbles: true,
        cancelable: true,
        view: window,
        relatedTarget: document
      })
      document.dispatchEvent(evt)
      document.dispatchEvent(evt1)
    }

    el.removeEventListener('scroll', listenerFn, false)
    el.addEventListener('scroll', listenerFn, false)
  }
}
